from common.base import Base, By, get_driver
import time

class UserPage(Base):
    userpage_url = "http://localhost:8080/ecshop/user.php"
    def shipping_address_click(self):
        """
        点击收货地址
        :return:
        """
        self.click((By.XPATH ,'/html/body/div[6]/div[1]/div/div/div/div/a[4]'))

    def user_center_click(self):
        """
        点击用户中心
        :return:
        """
        self.click((By.XPATH ,'/html/body/div[1]/div/div[2]/div[1]/a'))

    def distribution_area_select(self):
        """
        在表单中选择配送区域
        :return:
        """
        # 选择配送区域
        self.select((By.ID,'selCountries_0'),'1')
        self.select((By.ID,'selProvinces_0'),'24')
        self.select((By.ID,'selCities_0'),'271')
        self.select((By.ID,'selDistricts_0'),'2716')
    def name_input(self,name):
        # 在表单中输入收货人姓名
        self.send_keys((By.ID,'consignee_0'),name)
    def email_input(self,email):
        # 在表单中输入电子邮件地址
        self.send_keys((By.ID,'email_0'),email)
    def address_input(self,address):
        # 在表单中输入详细地址
        self.send_keys((By.ID,'address_0'),address)
    def address_value(self):
        # 定位表单中详细地址的文本并返回
        return self.attribute((By.ID,'address_0'),'value')

    def phone_input(self,phone):
        # 在表单中输入电话
        self.send_keys((By.ID,'tel_0'),phone)
    def add_btn_click(self):
        # 在表单中点击新增
        self.click((By.XPATH,'//form[1]/table/tbody/tr[5]/td[2]/input[1]'))
    def del_content(self):
        # 清除表单中的详细地址
        self.delete_content((By.ID,'address_0'))
    def change_btn_click(self):
        # 在表单中点击确认修改
        self.click((By.XPATH,'//form[1]/table/tbody/tr[5]/td[2]/input[1]'))
    def del_btn_click(self):
        # 在表单中点击删除,确认弹窗
        self.click((By.XPATH,'//form[1]/table/tbody/tr[5]/td[2]/input[2]'))
        self.alert_accept()
    def assert_text(self):
        """
        获取断言用的文本信息
        :return:
        """
        return self.text((By.XPATH,'/html/body/div[5]/div/div/div/div/p[1]'))

    def page_quit(self):
        self.quit()